/*
 * Copyright 2016-2019 yoara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package yhao.infra.feature.mail.core.entity;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 邮件发送实体类
 *
 * @author yoara
 */
public class Email {
    private boolean isText;                     //是否无模板纯文本邮件
    private String[] receivers;                 //邮件接收者
    private String[] cc;                        //邮件抄送人
    private String[] bcc;                       //邮件暗抄送人
    private String content;                     //Email发送的内容
    private Map<String, Object> param = new HashMap<>();  //邮件模板对象
    private String subject;                     //邮件主题
    private File[] attachFile;                  //邮件附件
    private MailTemplateCode templateCode;      //邮件模板定义

    protected Email(boolean isText) {
        this.isText = isText;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public File[] getAttachFile() {
        if (attachFile == null) {
            return new File[]{};
        }
        return attachFile;
    }

    public void setAttachFile(File[] attachFile) {
        this.attachFile = attachFile;
    }

    public String[] getReceivers() {
        return receivers;
    }

    public void setReceivers(String[] receivers) {
        this.receivers = receivers;
    }

    public String[] getCc() {
        return cc;
    }

    public void setCc(String... cc) {
        this.cc = cc;
    }

    public String[] getBcc() {
        return bcc;
    }

    public void setBcc(String... bcc) {
        this.bcc = bcc;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void addParam(String key,Object value){
        if(isText){
           throw new RuntimeException("this email is TextEmail，set content is enough");
        }
        param.put(key,value);
    }

    public void setParam(Map<String, Object> param) {
        this.param = param;
    }

    public Map<String, Object> getParam() {
        return param;
    }

    public boolean isText() {
        return isText;
    }

    public void setText(boolean text) {
        isText = text;
    }

    public MailTemplateCode getTemplateCode() {
        return templateCode;
    }

    public void setTemplateCode(MailTemplateCode templateCode) {
        this.templateCode = templateCode;
    }
}
